nethackfandomcom-20200214-history
Source:Dlb.h
Below is the full text to include/dlb.h from NetHack 3.4.3. To link to a particular line, write [[dlb.h#line123]], for example. 1. /* SCCS Id: @(#)dlb.h 3.4 1997/07/29 */ 2. /* Copyright © Kenneth Lorber, Bethesda, Maryland, 1993. */ 3. /* NetHack may be freely redistributed. See license for details. */ 4. 5. #ifndef DLB_H 6. #define DLB_H 7. /* definitions for data library */ 8. 9. #ifdef DLB 10. 11. /* implementations */ 12. #ifdef MAC 13. # define DLBRSRC /* use Mac resources */ 14. #else 15. # define DLBLIB /* use a set of external files */ 16. #endif 17. 18. #ifdef DLBLIB 19. /* directory structure in memory */ 20. typedef struct dlb_directory { 21. char *fname; /* file name as seen from calling code */ 22. long foffset; /* offset in lib file to start of this file */ 23. long fsize; /* file size */ 24. char handling; /* how to handle the file (compression, etc) */ 25. } libdir; 26. 27. /* information about each open library */ 28. typedef struct dlb_library { 29. FILE *fdata; /* opened data file */ 30. long fmark; /* current file mark */ 31. libdir *dir; /* directory of library file */ 32. char *sspace; /* pointer to string space */ 33. long nentries; /* # of files in directory */ 34. long rev; /* dlb file revision */ 35. long strsize; /* dlb file string size */ 36. } library; 37. 38. /* library definitions */ 39. # ifndef DLBFILE 40. # define DLBFILE "nhdat" /* name of library */ 41. # endif 42. # ifndef FILENAME_CMP 43. # define FILENAME_CMP strcmp /* case sensitive */ 44. # endif 45. 46. #endif /* DLBLIB */ 47. 48. 49. typedef struct dlb_handle { 50. FILE *fp; /* pointer to an external file, use if non-null */ 51. #ifdef DLBLIB 52. library *lib; /* pointer to library structure */ 53. long start; /* offset of start of file */ 54. long size; /* size of file */ 55. long mark; /* current file marker */ 56. #endif 57. #ifdef DLBRSRC 58. int fd; /* HandleFile file descriptor */ 59. #endif 60. } dlb; 61. 62. #if defined(ULTRIX_PROTO) && !defined(__STDC__) 63. /* buggy old Ultrix compiler wants this for the (*dlb_fread_proc) 64. and (*dlb_fgets_proc) prototypes in struct dlb_procs (dlb.c); 65. we'll use it in all the declarations for consistency */ 66. #define DLB_P struct dlb_handle * 67. #else 68. #define DLB_P dlb * 69. #endif 70. 71. boolean NDECL(dlb_init); 72. void NDECL(dlb_cleanup); 73. 74. dlb *FDECL(dlb_fopen, (const char *,const char *)); 75. int FDECL(dlb_fclose, (DLB_P)); 76. int FDECL(dlb_fread, (char *,int,int,DLB_P)); 77. int FDECL(dlb_fseek, (DLB_P,long,int)); 78. char *FDECL(dlb_fgets, (char *,int,DLB_P)); 79. int FDECL(dlb_fgetc, (DLB_P)); 80. long FDECL(dlb_ftell, (DLB_P)); 81. 82. 83. /* Resource DLB entry points */ 84. #ifdef DLBRSRC 85. boolean rsrc_dlb_init(void); 86. void rsrc_dlb_cleanup(void); 87. boolean rsrc_dlb_fopen(dlb *dp, const char *name, const char *mode); 88. int rsrc_dlb_fclose(dlb *dp); 89. int rsrc_dlb_fread(char *buf, int size, int quan, dlb *dp); 90. int rsrc_dlb_fseek(dlb *dp, long pos, int whence); 91. char *rsrc_dlb_fgets(char *buf, int len, dlb *dp); 92. int rsrc_dlb_fgetc(dlb *dp); 93. long rsrc_dlb_ftell(dlb *dp); 94. #endif 95. 96. 97. #else /* DLB */ 98. 99. # define dlb FILE 100. 101. # define dlb_init() 102. # define dlb_cleanup() 103. 104. # define dlb_fopen fopen 105. # define dlb_fclose fclose 106. # define dlb_fread fread 107. # define dlb_fseek fseek 108. # define dlb_fgets fgets 109. # define dlb_fgetc fgetc 110. # define dlb_ftell ftell 111. 112. #endif /* DLB */ 113. 114. 115. /* various other I/O stuff we don't want to replicate everywhere */ 116. 117. #ifndef SEEK_SET 118. # define SEEK_SET 0 119. #endif 120. #ifndef SEEK_CUR 121. # define SEEK_CUR 1 122. #endif 123. #ifndef SEEK_END 124. # define SEEK_END 2 125. #endif 126. 127. #define RDTMODE "r" 128. #if (defined(MSDOS) || defined(WIN32) || defined(TOS) || defined(OS2)) && defined(DLB) 129. #define WRTMODE "w+b" 130. #else 131. #define WRTMODE "w+" 132. #endif 133. #if (defined(MICRO) && !defined(AMIGA)) || defined(THINK_C) || defined(__MWERKS__) || defined(WIN32) 134. # define RDBMODE "rb" 135. # define WRBMODE "w+b" 136. #else 137. # define RDBMODE "r" 138. # define WRBMODE "w+" 139. #endif 140. 141. #endif /* DLB_H */ Category:source code